<?php
class BaiDuStoreSvc extends BaiDuCommon
{
    /*
        获取商户列表
        prarms

    */
    public function shopList()
    {
        $data = array();

        return $data;
    }

    /*
        请求获取商户列表
        params
            data 获取商户列表对象(shopList)
    */
    public function sendShopList($data = array())
    {
        $cmd = "shop.list";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("shop_list : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("shop_list_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        获取商户信息
        params
            shop_id 商户唯一id
    */
    public function getShopInfo($shop_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;

        return $data;
    }

    /*
        请求获取商户信息
        params
            data 获取商户信息对象(getShopInfo)
    */
    public function sendGetShopInfo($data = array())
    {
        $cmd = "shop.get";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("shop_info : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("shop_info_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        创建商户信息
        params
            base_info 药店基础(setBaseInfo)
            city_info 药店地址(cityInfo)
            business_time 药店营业时间(setBusinessTime)
            store_category 药店经营范围(getCategorys)
            extended_info 药店扩展信息(getExtendedInfo)
            region_info 药店配送区域(setRegionInfo)
    */
    public function addShopInfo($base_info = array(), $city_info = array(), $business_time = array(), $store_category = array(), $extended_info = array(), $region_info = array())
    {
        $data = array_merge(
            $base_info, 
            $city_info, 
            $business_time, 
            $store_category, 
            $extended_info, 
            $region_info 
        );

        return $data;
    }

    /*
        请求创建商户信息
        params
            data 创建商户信息对象(addShopInfo)
    */
    public function sendAddShopInfo($data = array())
    {
        $cmd = "shop.create";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("create_shop : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("create_shop_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        更新商户信息
        params
            shop_id 商户唯一id
            base_info 药店基础(setBaseInfo)
            city_info 药店地址(cityInfo)
            business_time 药店营业时间(setBusinessTime)
            store_category 药店经营范围(getCategorys)
            extended_info 药店扩展信息(getExtendedInfo)
            region_info 药店配送区域(setRegionInfo)
    */
    public function updateShopInfo($base_info = array(), $city_info = array(), $business_time = array(), $store_category = array(), $extended_info = array(), $region_info = array())
    {
        $data = array();
        $data['shop_id'] = $shop_id;

        $data = array_merge(
            $data,
            $base_info, 
            $city_info, 
            $business_time, 
            $store_category, 
            $extended_info, 
            $region_info 
        );

        return $data;
    }

    /*
        请求更新商户信息
        params
            data 更新商户信息对象(updateShopInfo)
    */
    public function sendUpdateShopInfo($data = array())
    {
        $cmd = "shop.update";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("update_shop : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("update_shop_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        下线商户
        params
            shop_id 店铺id
    */
    public function offlineShop($shop_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;

        return $data;
    }

    /*
        请求下线商户
        params
            data 下线商户对象(offlineShop)
    */
    public function sendOfflineShop($data = array())
    {
        $cmd = "shop.offline";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("offline_shop : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("offline_shop_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        商户开业
        params
            shop_id 商户唯一id
    */
    public function openShop($shop_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;

        return $data;
    }

    /*
        请求商户开业
        params
            data 商户开业对象(openShop)
    */
    public function sendOpenShop($data = array())
    {
        $cmd = "shop.open";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("open_shop : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("open_shop_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        商户歇业
        params
            shop_id 商户唯一id
    */
    public function closeShop($shop_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;

        return $data;
    }

    /*
        请求商户歇业
        params
            data 商户歇业对象(closeShop)
    */
    public function sendCloseShop($data = array())
    {
        $cmd = "shop.close";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("close_shop : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("close_shop_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        设置店铺公告
        params
            shop_id 商户唯一id
            content 公告内容 
    */
    public function setShopTopic($shop_id = '', $content = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['content'] = $content;

        return $data;
    }

    /*
        请求设置店铺公告
        params
            data 设置店铺公告对象(setShopTopic)
    */
    public function sendSetShopTopic($data = array())
    {
        $cmd = "shop.announcement.set";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("set_shop_topic : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("set_shop_topic_res : " . json_encode($res, JSON_UNESCAPED_UNICODE), "run", "channel_baidu");

        return $res['body'];
    }
    /*
        获取药店经营范围
        params

    */
    public function getCategorys()
    {
        $data = array();
        $data[0]['category1'] = "药店";
        $data[0]['category2'] = "药店";

        $res = array(
            "categorys" => $data
        );
        return $res;
    }

    /*
        获取药店所在城市
        params
            province 商户所在省份
            city 商户所在城市
            county 商户所在区县
            address 商户详细地址
            longitude 地址经度
            latitude 地址维度
    */
    public function setCityInfo($province = '', $city = '', $county = '', $address = '', $longitude = '', $latitude = '')
    {
        $data = array();
        $data['province'] = $province;
        $data['city'] = $city;
        $data['county'] = $county;
        $data['address'] = $address;
        $data['longitude'] = $longitude;
        $data['latitude'] = $latitude;
        $data['coord_type'] = "amap"; //坐标类型，可选值：bdll(百度)；amap(高德)

        return $data;
    }

    /*
        设置药店基础信息
        params
            shop_id 商户唯一id
            name 商户名称
            shop_logo 商户logo
            phone 商户电话 座机必须填写区号
            service_phone 客服电话
    */
    public function setBaseInfo($shop_id = '', $name = '', $shop_logo = '', $phone = '', $service_phone = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['name'] = $name;
        $data['shop_logo'] = $shop_logo;
        $data['phone'] = $phone;
        $data['service_phone'] = $service_phone;

        return $data;
    }

    /*
        获取扩展参数
        params

    */
    public function getExtendedInfo()
    {
        $data = array();
        $data['book_ahead_time'] = 0; //提前下单时间
        $data['invoice_support'] = 1; //是否可以提供发票，1：是 2：否
        $data['min_order_price'] = 0; //外卖起送价，单位：分
        $data['package_box_price'] = 0; //餐盒费，单位：分

        return $data;
    }

    /*
        设置营业时间
        params
            start 开始时间 格式HH:MM
            end 结束时间 格式HH:MM
    */
    public function setBusinessTime($start = '', $end = '')
    {
        $data = array();
        $data['start'] = $start;
        $data['end'] = $end;

        $res = array(
            "business_time" => array($data)
        );

        return $res;
    }

    /*
        设置配送区域经纬度信息
        params
            longitude 经度信息
            latitude 维度信息
    */
    public function setRegionPoint($longitude = 0, $latitude = 0)
    {
        $data = array();
        $data['longitude'] = $longitude;
        $data['latitude'] = $latitude;

        return $data;
    }

    /*
        设置配送区域信息
        params
            city 商户所在城市
            county 商户所在区县
            delivery_time 配送时长 单位分钟
            delivery_fee  配送费，单位：分
            region_point 配送区域经纬度信息
    */
    public function setRegionInfo($city = '', $county = '', $delivery_time = 0, $delivery_fee = 0, $region_point = array())
    {
        $data = array();
        $data['name'] = sprintf("%s%s配送区域", $city, $county);
        $data['delivery_fee'] = $delivery_fee;
        $data['delivery_time'] = $delivery_time;
        $data['delivery_fee'] = $delivery_fee;
        $data['region'] = array($region_point);

        $res = array(
            "delivery_region" => array($data)
        );
        return $res;
    }
}
?>